package  
{
	
	import org.flixel.*;
	
	/**
	 * ...
	 * @author Lucas
	 */
	public class Player extends FlxSprite
	{
		
		public var jumps:Number;
		public var direction:String;
		
		public function Player() 
		{
		super(100, FlxG.height - 100);
		this.maxVelocity.x = 240;
		this.maxVelocity.y = 440;
		this.makeGraphic(32, 32, 0xFFFF8040);
		this.acceleration.y = 500;
		this.drag.x = this.maxVelocity.x * 4;
		}
		
		override public function update():void {
			
			super.update();
			
			this.acceleration.x = 0;
			
			if (FlxG.keys.LEFT) {
				this.acceleration.x = -this.maxVelocity.x * 4;
				direction = "left";
			}
			if (FlxG.keys.RIGHT) {
				this.acceleration.x = this.maxVelocity.x * 4;
				direction = "right"
			}
			
			if (this.isTouching(FlxObject.FLOOR)) {
				jumps = 0;
			}
			
			if (FlxG.keys.justPressed("UP")) {
				// single and double jump
				if ((jumps == 0) || (jumps == 1)) {
					jumps++;
					this.velocity.y = -this.maxVelocity.y/2.5;
				}
				// wall jump
				if (this.isTouching(WALL) && !this.isTouching(FLOOR)) {
					this.velocity.y = -this.maxVelocity.y/3;
					jumps++;
					if (direction == "right") {
						this.velocity.x = -this.maxVelocity.x*8;
					}
					if (direction == "left") {
						this.velocity.x = this.maxVelocity.x*8;
					}
				}
				
			}
		
	}
	}

}